package model

import (
	"common/globals"
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Tel    string `gorm:"column:tel;type:char(11);not null;unique" json:"tel"`
	Passwd string `gorm:"column:passwd;type:char(32);not null" json:"passwd"`
	Level  int    `gorm:"column:level;type:int(11);not null;default:0" json:"level"`
	Points int    `gorm:"column:points;type:int(11);not null;default:0" json:"points"`
}

func (u *User) TableName() string {
	return "user"
}
func (u *User) GetUserInfoById(id int) error {
	return globals.Db.Where("id = ?", id).Limit(1).Find(&u).Error
}
func (u *User) GetUserInfoByTel(tel string) error {
	return globals.Db.Where("tel = ?", tel).Limit(1).Find(&u).Error
}
func (u *User) UpdateUserPointsById(id int, points int) error {
	return globals.Db.Model(&User{}).Where("id = ?", id).Update("points", points).Error
}
